package c0907m.group2.aitsm.core.report;

import c0907m.group2.aitsm.util.Helper;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.view.JasperViewer;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Author: LongDH
 * Date: 5/6/11
 * Time: 2:37 PM
 * <p/>
 * Base class contains common methods for all Reporters.
 */
public abstract class BaseReporter {
    protected Map<String, String> params = new HashMap<String, String>();
    protected String where = "";
    protected String filename;

    /**
     * Build and view this report.
     *
     * @throws JRException  if unable to build.
     * @throws SQLException if a database access error occurs
     */
    public void view() throws JRException, SQLException {
        if (where.length() > 0) params.put("where", where);
        JasperViewer.viewReport(JasperFillManager.fillReport(filename, params, Helper.getConnection()), false);
    }
}
